package com.chixing.util;

/*
*
* */
public class ServerResponse {
    private int code;  //结果状态：200 处理成功，201 处理失败
    private String reason; //结果的描述
    private Object data; //返回的结果

    public ServerResponse(){}
    public ServerResponse(int code, String reason, Object data) {
        this.code = code;
        this.reason = reason;
        this.data = data;
    }

    public static ServerResponse saveSucccess(Object data){
        return new ServerResponse(200,"添加成功",data);
    }
    public static ServerResponse saveFail(Object data){
        return new ServerResponse(201,"添加失败",data);
    }
    public static ServerResponse getSucccess(Object data){
        return new ServerResponse(200,"获得成功",data);
    }
    public static ServerResponse getFail(Object data){
        return new ServerResponse(201,"获得失败",data);
    }
    public static ServerResponse updateSucccess(Object data){
        return new ServerResponse(200,"修改成功",data);
    }
    public static ServerResponse updateFail(Object data){
        return new ServerResponse(201,"修改失败",data);
    }
    public static ServerResponse deleteSucccess(Object data){
        return new ServerResponse(200,"删除成功",data);
    }
    public static ServerResponse deleteFail(Object data){
        return new ServerResponse(201,"删除失败",data);
    }
    public static ServerResponse getByPageSucccess(Object data){
        return new ServerResponse(200,"分页成功",data);
    }
    public static ServerResponse getByPageFail(Object data){
        return new ServerResponse(201,"分页失败",data);
    }






    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ServerResponse{" +
                "code=" + code +
                ", reason='" + reason + '\'' +
                ", data=" + data +
                '}';
    }
}
